#define _XOPEN_SOURCE

#include <io_utils.h>
#include <time_utils.h>
#include <time.h>

int main() {
  //是个格式不正确导致问题
  //char *time = "2020-11-10 90:80:32.123";
  //正确
  char *time = "2020-11-10 10:45:32.123";
  struct tm parsed_time;
  //unix
  char *unparsed_string = strptime(time, "%F %T", &parsed_time);
  PRINT_STRING(unparsed_string);
  PRINT_INT(parsed_time.tm_year);
  PRINT_INT(parsed_time.tm_mon);
  PRINT_INT(parsed_time.tm_mday);
  PRINT_INT(parsed_time.tm_hour);
  PRINT_INT(parsed_time.tm_min);
  PRINT_INT(parsed_time.tm_sec);


// msvc
  int millisecond;
  sscanf(time, "%4d-%2d-%2d %2d:%2d:%2d.%3d",
         &parsed_time.tm_year,
         &parsed_time.tm_mon,
         &parsed_time.tm_mday,
         &parsed_time.tm_hour,
         &parsed_time.tm_min,
         &parsed_time.tm_sec,
         &millisecond);

  parsed_time.tm_year -= 1900;
  parsed_time.tm_mon -= 1;

  mktime(&parsed_time);

  PRINT_INT(parsed_time.tm_year);
  PRINT_INT(parsed_time.tm_mon);
  PRINT_INT(parsed_time.tm_mday);
  PRINT_INT(parsed_time.tm_hour);
  PRINT_INT(parsed_time.tm_min);
  PRINT_INT(parsed_time.tm_sec);
  PRINT_INT(millisecond);

//  puts(unparsed_string);
//  sscanf(unparsed_string, ".%3d", &millisecond);
//  PRINT_INT(millisecond);


  return 0;
}
